var express = require('express')
var cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
var fs = require('fs')
var app = express()
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json())
// app.use(cookieParser)
var router = express.Router() 
router.get('/', (req, res) =>{
  res.send('ok')
})
router.get('/login',(req, res)=> {
  console.log('geet')
  fs.readFile(__dirname+'/login.html', function(err,data){
    if(err){
      console.log(err)
      return
    }
  //  res.writeHead(200,{'content-type': 'text/html'})
   res.writeHead(200)
    res.write(data)
   res.end()
  })
})
router.post('/login', (req, res,next) => {
  console.log(req.body)
  res.send(`name is ${req.body.name} password is ${req.body.password}`)
  next()
})

app.use('/', router)

app.listen(3001,(err,data)=>{
  if(err){
    console.log(err)
  }else {
    console.log('启动成功')
  }
}) 
app.on('err',function(err){
  console.log(err)
})